package com.jiamao.goplay.ui.discover.vm;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.jiamao.goplay.adapter.NearbyAdapter;
import com.jiamao.goplay.app.AppApplication;
import com.jiamao.goplay.bean.NearbyItem;
import com.jiamao.goplay.ui.discover.AddrDetailFragment;
import com.jiamao.goplay.ui.login.LoginPhoneSMSFragment;
import com.jiamao.goplay.util.StringUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.KLog;

public class NeayByItemVM extends MultiItemViewModel {

    private DecimalFormat decimalFormat=new DecimalFormat(".00");
    public ObservableField<String> imgUrl = new ObservableField<>("");
    public ObservableField<String> name = new ObservableField<>("");
    public ObservableField<String> addr = new ObservableField<>("");
    public ObservableField<String> gotoNum = new ObservableField<>("");
    public ObservableField<Float> rat = new ObservableField<Float>();
    public ObservableField<String> rank = new ObservableField<String>();


    public ObservableInt addBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt removeBtnVisibility = new ObservableInt(View.GONE);


    public int status=0;
    public ArrayList<String> pig = new ArrayList<>();
    private NearbyItem data;
    public NeayByItemVM(@NonNull BaseViewModel viewModel, NearbyItem item) {
        super(viewModel);
        if (item == null) {
            return;
        }
        this.data = item;
        this.status = item.getStatus();
        imgUrl.set(item.getPhoto());
        name.set(item.getName());
        rat.set(item.getRating());
        gotoNum.set(StringUtils.formatBigNum(item.getNum()) + "人想去");
        float distance = 0;
        pig = item.getAvatars();
        if (item.getCost() == 0){
            rank.set("");
        }else {
            rank.set("¥" + item.getCost() + "/人");
        }
      //  rank.set("¥" + item.getCost() + "/人");
        String type = item.getCategory();

        addr.set(item.getDistance() + "km，" + type + "，" + item.getCity()+item.getArea());

        if (status == 1){
            removeBtnVisibility.set(View.VISIBLE);
        }else {
            addBtnVisibility.set(View.VISIBLE);
        }

    }


    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {


            if (data==null){
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putString("id",data.getPlaceId());
            viewModel.startContainerActivity(AddrDetailFragment.class.getCanonicalName(),bundle);


          //  viewModel.startContainerActivity(AddrDetailFragment.class.getCanonicalName());
         //   ToastUtils.showShort("我是头布局");
        }
    });




    //条目的点击事件
    public BindingCommand addClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {


            if (viewModel instanceof NeayByVM){
                ((NeayByVM)viewModel).addCloection(data.getPlaceId(),NeayByItemVM.this);
            }
            else if (viewModel instanceof CityGoToVM){
                ((NeayByVM)viewModel).addCloection(data.getPlaceId(),NeayByItemVM.this);
            }

            //Model.startContainerActivity(AddrDetailFragment.class.getCanonicalName());
            //   ToastUtils.showShort("我是头布局");
        }
    });

    //条目的点击事件
    public BindingCommand removeClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {


            if (viewModel instanceof NeayByVM){
                ((NeayByVM)viewModel).removeCloection(data.getPlaceId(),NeayByItemVM.this);
            }

           else if (viewModel instanceof CityGoToVM){
                ((NeayByVM)viewModel).removeCloection(data.getPlaceId(),NeayByItemVM.this);
            }



            //Model.startContainerActivity(AddrDetailFragment.class.getCanonicalName());
            //   ToastUtils.showShort("我是头布局");
        }
    });
}
